<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.11"/>
<title>GrPPI: Reduce pattern</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<script type="text/javascript">
  $(document).ready(function() { init_search(); });
</script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td id="projectlogo"><img alt="Logo" src="logo.svg"/></td>
  <td id="projectalign" style="padding-left: 0.5em;">
   <div id="projectname">GrPPI
   &#160;<span id="projectnumber">0.2</span>
   </div>
   <div id="projectbrief">Generic and Reusable Parallel Pattern Interface</div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.11 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'Search');
</script>
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li class="current"><a href="pages.html"><span>Related&#160;Pages</span></a></li>
      <li><a href="modules.html"><span>Modules</span></a></li>
      <li><a href="namespaces.html"><span>Namespaces</span></a></li>
      <li><a href="annotated.html"><span>Classes</span></a></li>
      <li><a href="files.html"><span>Files</span></a></li>
      <li>
        <div id="MSearchBox" class="MSearchBoxInactive">
        <span class="left">
          <img id="MSearchSelect" src="search/mag_sel.png"
               onmouseover="return searchBox.OnSearchSelectShow()"
               onmouseout="return searchBox.OnSearchSelectHide()"
               alt=""/>
          <input type="text" id="MSearchField" value="Search" accesskey="S"
               onfocus="searchBox.OnSearchFieldFocus(true)" 
               onblur="searchBox.OnSearchFieldFocus(false)" 
               onkeyup="searchBox.OnSearchFieldChange(event)"/>
          </span><span class="right">
            <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
          </span>
        </div>
      </li>
    </ul>
  </div>
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

</div><!-- top -->
<div class="header">
  <div class="headertitle">
<div class="title">Reduce pattern </div>  </div>
</div><!--header-->
<div class="contents">
<div class="textblock"><p>The <b>reduce</b> pattern is a data pattern that combines all the values in a data set using a binary combination operation.</p>
<p>The interface to the <b>reduce</b> pattern is provided by function <code><a class="el" href="group__reduce__pattern__native.html#gad3a9dc3cdb2b5165d1cc201eb0da4383" title="Invoke Reduce pattern with identity value on a data sequence with parallel native execution...">grppi::reduce()</a></code>. As all functions in <em>GrPPI</em>, this function takes as its first argument an execution policy.</p>
<div class="fragment"><div class="line"><a class="code" href="group__reduce__pattern__native.html#gad3a9dc3cdb2b5165d1cc201eb0da4383">grppi::reduce</a>(exec, other_arguments...);</div></div><!-- fragment --><h2>Reduction variants</h2>
<p>There is a single variant of the reduction:</p>
<ul>
<li><b>Sequence reduction without initial value</b>: Reduces a sequence of values with no initial value.</li>
<li><b>Sequence reduction with initial value</b>: Reduces a sequence of values with an initial value.</li>
</ul>
<h2>Key elements in a reduction</h2>
<p>The key element of a reduction is the <b>Combiner</b> operation.</p>
<p>A <b>Combiner</b> is any C++ callable entity, that is able to combine two values into a single value. A <b>Combiner</b> <code>cmb</code> is any operation taking two values <code>x</code> and <code>y</code> of types <code>T</code> and <code>U</code> and returning a combined value of type <code>T</code>, making valid the following:</p>
<div class="fragment"><div class="line">T x;</div><div class="line">U y;</div><div class="line">T res = cmb(x,y);</div></div><!-- fragment --><h2>Details on reduction variants</h2>
<h3>Sequence reduction with identity</h3>
<p>Performs a reduction of a sequence of values <code>x1, x2, ..., xN</code> by combining them with a <b>Combiner</b> <code>cmb</code> that has an identity value <code>id</code>. The first argument of a combination may be either the identity value or the result of another combination. The combinations assume that <code>cmb</code> is <em>associative</em>, but not commutative. Consequently, different associative orders may be used:</p>
<ul>
<li><code>cmb(cmb(cmb(cmb(cmb(id,x1),x2),x3), ...),xN)</code></li>
<li><code>cmb(cmb(cmb(cmb(id,x1),x2),cmb(cmb(id,x3),x4)),...)</code></li>
<li>...</li>
</ul>
<p>The only interface currently offered for this pattern is based in iterators (following the C++ standard library conventions):</p>
<ul>
<li>The input data set is specified by two iterators.</li>
<li>The identity value is provided as an input value.</li>
<li>The result of the reduction is returned. <hr/>
 <b>Example</b>: Add the lenghts of a sequence of strings. <div class="fragment"><div class="line">vector&lt;string&gt; v = get_the_vector();</div><div class="line"><span class="keyword">auto</span> result = <a class="code" href="group__reduce__pattern__native.html#gad3a9dc3cdb2b5165d1cc201eb0da4383">reduce</a>(exec,</div><div class="line">  begin(v), end(ve), 0</div><div class="line">  [](<span class="keywordtype">int</span> n, <span class="keywordtype">string</span> s) { <span class="keywordflow">return</span> n + s.length(); }</div><div class="line">);</div></div><!-- fragment --><hr/>
</li>
</ul>
<p><b>Note</b>: Reducing with identity value an empty sequence has a result the identity value. </p>
</div></div><!-- contents -->
<!-- start footer part -->
<hr class="footer"/><address class="footer"><small>
Generated by &#160;<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/>
</a> 1.8.11
</small></address>
</body>
</html>
